﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;

namespace University.Workshop.WinApp
{
    public partial class CreateNoteBook : Form
    {
        bool isValid = false;
        private string oldItem;
        public CreateNoteBook()
        {
            InitializeComponent();
            buttonChange.Visible = false;
        }

        public CreateNoteBook(string itemSelected)
        {
            // TODO: Complete member initialization
            InitializeComponent();
            buttoSave.Visible = false;
            oldItem = itemSelected;
            textBoxNoteBook.Text = oldItem;
            isValid = true;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttoSave_Click(object sender, EventArgs e)
        {
            if (isValid==true && !string.IsNullOrEmpty(textBoxNoteBook.Text))
            {
                if (AgendaManager.NewAgenda(textBoxNoteBook.Text))
                {
                    MessageBox.Show("Successful registration");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("The NoteBook could not be registered");
                }
            }
            else 
            {
                MessageBox.Show("Error NoteBook");
            }
        }

        private void textBoxNoteBook_Validating(object sender, CancelEventArgs e)
        {
            isValid = ValidateFields.SearchFieldValidation(textBoxNoteBook.Text);
        }

        private void buttonChange_Click(object sender, EventArgs e)
        {
            if (isValid == true && !string.IsNullOrEmpty(textBoxNoteBook.Text))
            {
                if (AgendaManager.ModifyAgenda(textBoxNoteBook.Text,oldItem))
                {
                    MessageBox.Show("Successful registration");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("The NoteBook could not be registered");
                }
            }
            else
            {
                MessageBox.Show("Error NoteBook");
            }
        }
    }
}
